﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Transport;
using System.IO;

namespace iLangl.Transport.Communication
{
	public class PackagesRobotSent : BaseRobotOperation, IRobotSet
	{
		protected ITransport _transport;
		public PackagesRobotSent(IRobot robot, ITransport transport)
			: base(robot) 
		{
			_transport = transport;
		}
		#region IRobotSet Members


		protected override void execute(IPackage package, FileInfo fileinfo)
		{
			UploadRequest uploadRequest = new UploadRequest();

			uploadRequest.LicenseKey = package.PluginLiceneKey;
			uploadRequest.PackageId = package.Id;
			uploadRequest.PackageSize = fileinfo.Length;
			uploadRequest.DeliveredFileName = fileinfo.Name;

			using (FileStream fstream = new FileStream(fileinfo.FullName, FileMode.Open))
			{
				uploadRequest.PackageData = fstream;
				_transport.SendRequest(uploadRequest);
			}

		}

		#endregion
	}
}
